package com.icbc.open.chengdu.demo.account.query;

import com.csii.pp.icbc.util.Util;
import com.icbc.api.DefaultIcbcClient;
import com.icbc.api.internal.util.internal.util.fastjson.JSON;
import com.icbc.open.chengdu.demo.BaseData;
import com.icbc.open.chengdu.demo.utils.GenerateKeyUtils;
import com.icbc.open.chengdu.demo.utils.SecretUtils;

import com.icbc.api.request.SettlementAccountInfoQueryRequestV1;
import com.icbc.api.request.SettlementAccountInfoQueryRequestV1.SettlementAccountInfoQueryRequestV1Biz;
import com.icbc.api.response.SettlementAccountInfoQueryResponseV1;

/**
 * 结算账户详情查询
 *
 * @author xcz
 */
public class SettlementAccountInfoQueryTest {
	public static void main(String[] args) throws Exception {
		String sm4Key = GenerateKeyUtils.generateSM4Key(); //生成SM4密钥
		DefaultIcbcClient client = new DefaultIcbcClient(BaseData.APP_ID, BaseData.MY_RSA_PRIVATE_KEY, BaseData.ICBC_RSA_PUBLIC_KEY);
		SettlementAccountInfoQueryRequestV1 request = new SettlementAccountInfoQueryRequestV1();
		SettlementAccountInfoQueryRequestV1Biz bizContent = new SettlementAccountInfoQueryRequestV1Biz();
		request.setServiceUrl(BaseData.ACCOUNT_INFO_QUERY_URL);//url
		bizContent.setCorpNo(BaseData.APP_ID); //合作方机构编号
		bizContent.setTrxAccDate(BaseData.TEST_TRX_ACC_DATE);//合作方交易日期
		bizContent.setTrxAccTime(BaseData.TEST_TRX_ACC_TIME);//合作方交易时间
		bizContent.setCorpSerno(Util.getNonceStr(16)); //合作方交易单号
		bizContent.setCorpDate(BaseData.TEST_CORP_DATE); //合作方工作日期
		bizContent.setOutServiceCode("queryinfo");
		bizContent.setMediumId(SecretUtils.encryptSM4(sm4Key, BaseData.TEST_ACCOUNT_NUMBER_2));//工行联名卡号
		bizContent.setSecretKey(SecretUtils.encryptSM2(sm4Key));//密钥
		request.setBizContent(bizContent);
		SettlementAccountInfoQueryResponseV1 response = client.execute(request);
		System.out.println(JSON.toJSONString(response));
		if (response.isSuccess()) {
			System.out.println("用户名：" + SecretUtils.decryptMediumId(response.getCustName(), response.getSecretKey()));
			System.out.println("证件号：" + SecretUtils.decryptMediumId(response.getCertNo(), response.getSecretKey()));
		} else {
		}

	}
}
